home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9536 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: oitnews.harvard.edu!cmcl2!news!schonberg!dewar
  2. From: dewar@cs.nyu.edu (Robert Dewar)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c
  4. Subject: Re: Hungarian notation - whoops!
  5. Date: 2 Mar 1996 09:19:33 -0500
  6. Organization: Courant Institute of Mathematical Sciences
  7. Message-ID: <dewar.825776096@schonberg>
  8. References: <30C40F77.53B5@swsbbs.com> <4fc157$jsf@goanna.cs.rmit.EDU.AU> <dewar.823793746@schonberg> <4fms62$c0p@goanna.cs.rmit.EDU.AU> <4ft1ruINN6dr@keats.ugrad.cs.ubc.ca> <4g9255$74s@goanna.cs.rmit.EDU.AU> <824909942snz@genesis.demon.co.uk> <4h6gbp$guh@goanna.cs.rmit.EDU.AU>
  9. NNTP-Posting-Host: schonberg.cs.nyu.edu
  10. X-Newsreader: NN version 6.5.0 (NOV)
  11.  
  12. Richard O'Keefe said
  13.  
  14. "I have implemented multiple-precision arithmetic, and I must say I found
  15. 2s-complement a confounded nuisance.  What I wanted, and what I used,
  16. was arithmetic on N-bit natural numbers with overflow.  In short, what
  17. I wanted for multiple precision arithmetic was
  18.         N-bit natural + N-bit natural -> N-bit natural + carry
  19.         N-bit natural - N-bit natural -> N-bit natural + borrow
  20.         N-bit natural x N-bit natural -> 2N-bit natural
  21.         2N-bit natural (/,%) N-bit natural -> N-bit natural, N-bit natural
  22. Interpreting any of these as signed gave rise to serious complications."
  23.  
  24. This makes me think that you don't understand the point. What you say above
  25. is that for multiple-precision you need unsigned arithmetic, and that signs
  26. get in the way. But the whole point is that TWOS COMPLEMENT ARITHMETIC IS
  27. IDENTICAL TO UNSIGNED (for addition and subtraction).
  28.  
  29. If you had trouble from 2s-complement arithmetic in this context, it must
  30. have been because you were confused ..
  31.  
  32. Using sign-and-magnitued arithmetic for multiple-precision implementation
  33. is a real pain, and in fact most, but not all, S&M machines have separate
  34. unsigned arithmetic instructions (or I should say had, since S&M machines
  35. have for the most part disappeared from sight, and good riddence!)
  36.  
  37. As for the claim that you don't have to check for overflow in negation,
  38. that's preetty much irrelevant in practice, since in a properly 
  39. written program with reasonable types, there is no reason that the range
  40. of your data should correspond to machine ranges anyway.
  41.  
  42.    type x is range -10 .. + 10;
  43.    type y is range -3 .. +7;
  44.  
  45. type x requires no overflow check for negation, regardless of the
  46. underying representation on the machine, and type y requires an
  47. overflow check for negation, regardless of the underlying 
  48. representation on the machine.
  49.  
  50.